package com.ruoyi.omp.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.omp.api.RemoteLeaseRecordService;
import com.ruoyi.omp.api.domain.FeLeaseRecord;
import com.ruoyi.omp.api.domain.vo.RoomVO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * 租赁记录降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteLeaseRecordFactory implements FallbackFactory<RemoteLeaseRecordService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteLeaseRecordFactory.class);

    @Override
    public RemoteLeaseRecordService create(Throwable throwable) {
        log.error("租赁记录房源服务调用失败:{}", throwable.getMessage());
        return new RemoteLeaseRecordService() {
            @Override
            public R addLeaseRecord(@RequestBody FeLeaseRecord feLeaseRecord) {
                return R.fail("新增租赁记录失败:" + throwable.getMessage());
            }

            @Override
            public R delRecordByEnterpriseId(String enterpriseId) {
                return R.fail("删除租赁记录失败:" + throwable.getMessage());
            }

            /**
             * 修改租赁记录
             *
             * @param leaseRecord 租赁记录
             * @return
             */
            @Override
            public R updateLeaseRecord(FeLeaseRecord leaseRecord) {
                return R.fail("修改租赁记录失败:" + throwable.getMessage());
            }

            /**
             * 查询租赁记录列表
             *
             * @param feLeaseRecord 租赁记录
             * @return
             */
            @Override
            public R<List<FeLeaseRecord>> listRecord(FeLeaseRecord feLeaseRecord) {
                return R.fail("查询租赁记录失败:" + throwable.getMessage());
            }

            @Override
            public R<FeLeaseRecord> getLeaseRecordByEnterprise(String enterpriseId) {
                return R.fail("查询租赁记录失败:" + throwable.getMessage());
            }

            @Override
            public R<List<FeLeaseRecord>> getRecordListByEnterpriseId(String enterpriseId) {
                return R.fail("根据企业ID查询租赁记录失败:" + throwable.getMessage());
            }

            /**
             * 通过租赁记录查询对应房屋信息
             *
             * @param recordId 租赁记录id
             * @return
             */
            @Override
            public R<List<RoomVO>> selectRoomByRecordId(String recordId) {
                return R.fail("查询租赁记录房屋失败:" + throwable.getMessage());
            }
        };


    }
}
